/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * @author ZhangMaoren 
 * @since 2015年6月23日
 * @version 0.1
 */
package com.suredy.base.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.suredy.core.model.BaseModel;


/**
 * @author ZhangMaoren
 *
 */
@Entity
@Table(name = "T_SECURITY_USER2PERMISSION")
public class User2Permission extends BaseModel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4480816221820960092L;
	
	@Column(name = "USERID", length = 32)
	private String userId;
	
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "PERMISSIONID")
	private Permission userPermission;
	
	
	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}

	
	/**
	 * @param userId the userId to set
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}

	

	
	/**
	 * @return the userPermission
	 */
	public Permission getUserPermission() {
		return userPermission;
	}


	
	/**
	 * @param userPermission the userPermission to set
	 */
	public void setUserPermission(Permission userPermission) {
		this.userPermission = userPermission;
	}


	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		User2Permission that = (User2Permission) o;

		if (id != null ? !id.equals(that.id) : that.id != null) {
			return false;
		}
		if (userPermission != null ? !userPermission.equals(that.userPermission)
				: that.userPermission != null) {
			return false;
		}
		if (userId != null ? !userId.equals(that.userId)
				: that.userId != null) {
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {
		int result = id != null ? id.hashCode() : 0;
		result += (userId != null ? userId.hashCode() : 0);
		result += (userPermission != null ? userPermission.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "User2Permission[id=" + id + ", userId=" + userId + ", userPermission="
				+ userPermission + "]";
	}

}
